//package com.sdhs.mob.front.wechat.service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.sdhs.mob.common.bean.HighWayPO;
//import com.sdhs.mob.common.constant.BusinessConstant;
//import com.sdhs.mob.common.constant.OrderNoConstant;
//import com.sdhs.mob.common.constant.SysParamConstant;
//import com.sdhs.mob.common.mapper.HighWayMapper;
//import com.sdhs.mob.common.mapper.OilModelMapper;
//import com.sdhs.mob.common.service.ExceptionSevice;
//import com.sdhs.mob.common.utils.RequestUtil;
//import com.sdhs.mob.common.utils.SysParamsUtil;
//import com.sdhs.mob.front.estation.base.bean.po.EsUserPO;
//import com.sdhs.mob.front.estation.base.mapper.UserInfoMapper;
//import com.sdhs.mob.front.estation.base.utils.EStationUtils;
//import com.sdhs.mob.front.estation.gasstation.bean.po.GasStationPO;
//import com.sdhs.mob.front.estation.gasstation.mapper.GasStationMapper;
//import com.sdhs.mob.front.estation.invoice.bean.po.InvoiceRecordPO;
//import com.sdhs.mob.front.estation.invoice.mapper.InvoiceRecordMapper;
//import com.sdhs.mob.front.estation.oilcard.bean.po.BillConsumePO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.BillRechargePO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.OilCardPO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.OilCouponPO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.OilCouponPutPO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.OilModelPO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.OilQrCodePO;
//import com.sdhs.mob.front.estation.oilcard.bean.po.OilStationPO;
//import com.sdhs.mob.front.estation.oilcard.mapper.BillConsumeMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.BillRechargeMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.EsUserMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.GasStationOilPriceMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.MarketPriceMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.OilCardMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.OilCouponPoMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.OilCouponPutMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.OilQrCodeMapper;
//import com.sdhs.mob.front.estation.oilcard.mapper.OilStationMapper;
//import com.sdhs.mob.front.wechat.bo.BalanceResponseBO;
//import com.sdhs.mob.front.wechat.bo.BillResponseBO;
//import com.sdhs.mob.front.wechat.bo.ConsOrderResponseBO;
//import com.sdhs.mob.front.wechat.bo.GasStationListResponseBO;
//import com.sdhs.mob.front.wechat.bo.InitiatingRechargeRequestBO;
//import com.sdhs.mob.front.wechat.bo.InvoiceHistoryResponseBO;
//import com.sdhs.mob.front.wechat.bo.InvoiceWriteOffRequestBO;
//import com.sdhs.mob.front.wechat.bo.InvoicesRequestBO;
//import com.sdhs.mob.front.wechat.bo.MarketPriceInfo;
//import com.sdhs.mob.front.wechat.bo.MemberCenterResponseBO;
//import com.sdhs.mob.front.wechat.bo.OilStationRequestBO;
//import com.sdhs.mob.front.wechat.bo.RechargeDetailsBO;
//import com.sdhs.mob.front.wechat.bo.RechargeResponseBO;
//import com.sdhs.mob.front.wechat.bo.TransRecordResponseBO;
//import com.sdhs.mob.front.wechat.mapper.WeChatMapper;
//import com.sdhs.mob.front.wechat.service.WeChatService;
//import com.sdhs.mob.front.wechat.util.GetWxOrderno;
//import com.sdhs.mob.front.wechat.util.SampleMail;
//import com.sdhs.mob.front.wechat.util.ThreadUtil;
//import com.sdhs.mob.front.wechat.util.WechatMsgUtil;
//import com.sdhs.mob.front.wechat.util.WechatUtil;
//import com.sdhs.mob.front.wechat.util.WxPayUtil;
//import com.sdhs.mob.utils.CdkeyUtil;
//import com.sdhs.mob.utils.DateUtil;
//import com.sdhs.mob.utils.HttpClientUtil;
//import com.sdhs.mob.utils.MapDistanceUtil;
//import com.sdhs.mob.utils.OrderNoUtil;
//import com.sdhs.mob.xinlian.service.XlCoreService;
//import com.sdhs.mob.xinlian.service.impl.XlInvoiceServlet;
//import com.sdhs.xinlianjiayou.pos.constant.PosResponseCodeEnum;
//import com.sdhs.xinlianjiayou.pos.msg.Msg3123;
//import org.apache.commons.codec.binary.Hex;
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
//import org.apache.pdfbox.pdmodel.PDDocument;
//import org.apache.pdfbox.rendering.ImageType;
//import org.apache.pdfbox.rendering.PDFRenderer;
//import org.dom4j.Document;
//import org.dom4j.io.SAXReader;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.ObjectUtils;
//
//import javax.crypto.Mac;
//import javax.crypto.spec.SecretKeySpec;
//import javax.imageio.ImageIO;
//import javax.print.DocFlavor;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.xml.parsers.DocumentBuilderFactory;
//import java.awt.image.BufferedImage;
//import java.io.BufferedInputStream;
//import java.io.ByteArrayInputStream;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.math.BigDecimal;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.net.URLConnection;
//import java.nio.charset.Charset;
//import java.security.MessageDigest;
//import java.text.SimpleDateFormat;
//import java.util.*;
//
///**
// * @author genglong
// */
//
///**
// * @author genglong
// */
//@Service("weChatService")
//public class WeChatServiceImpl implements WeChatService {
//
//    private static Logger LOGGER = LogManager.getLogger(WeChatServiceImpl.class);
//
//    /**
//     * 订单类型：1-充值，2-消费
//     */
//    private static int ORDER_TYPE = 2;
//
//    @Autowired
//    private WeChatMapper weChatMapper;
//
//    @Autowired
//    private OilCardMapper oilCardMapper;
//
//    @Autowired
//    private XlCoreService xlCoreService;
//
//    @Autowired
//    private XlInvoiceServlet xlInvoiceServlet;
//
//    @Autowired
//    private BillRechargeMapper billRechargeMapper;
//
//    @Autowired
//    private InvoiceRecordMapper invoiceRecordMapper;
//    @Autowired
//    private GasStationMapper gasStationMapper;
//
//    @Autowired
//    private ExceptionSevice exceptionSevice;
//
//    @Autowired
//    private MarketPriceMapper marketPriceMapper;
//
//    @Autowired
//    private HighWayMapper highWayMapper;
//
//    @Autowired
//    private OilModelMapper oilModelMapper;
//
//    @Autowired
//    private OilStationMapper oilStationMapper;
//
//    @Autowired
//    private BillConsumeMapper billConsumeMapper;
//
//    @Autowired
//    private GasStationOilPriceMapper gasStationOilPriceMapper;
//
//    @Autowired
//    private OilCouponPutMapper oilCouponPutMapper;
//
//    @Autowired
//    private OilCouponPoMapper oilCouponPoMapper;
//    @Autowired
//    private EsUserMapper esUserMapper;
//
//    @Autowired
//    private OilQrCodeMapper oilQrCodeMapper;
//
//    @Autowired
//    private UserInfoMapper userInfoMapper;
//
//    /**
//     * 上传凭证
//     */
//    private static final String UP_TOKEN = generateUpToken();
//
//    @Override
//    @SuppressWarnings("unchecked")
//    public <T> T parseRequest(HttpServletRequest request) throws Exception {
//        String encryptJson = RequestUtil.getString(request);
//        if (StringUtils.isEmpty(encryptJson)) {
//            LOGGER.info("... . . .-. 请求参数为空 {}", encryptJson);
//        }
//        return (T) JSONObject.parseObject(encryptJson);
//    }
//
//    /**
//     * 交易记录
//     */
//    @Override
//    public List<TransRecordResponseBO> findTransRecordList(HttpServletRequest request) throws Exception {
//        JSONObject jsonObject = this.parseRequest(request);
//        int page_num = Integer.valueOf(jsonObject.getString("page_num"));
//        int limit = Integer.valueOf(jsonObject.getString("page_size"));
//        int offset = limit * (page_num - 1);
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        List<TransRecordResponseBO> list = weChatMapper.findTransRecordList(cardId, offset, limit);
//        if (list == null || list.size() <= 0) {
//            return new ArrayList<>();
//        }
//        for (TransRecordResponseBO transRecordResponseBO : list) {
//            int orderType = transRecordResponseBO.getOrder_type();
//            if (orderType != ORDER_TYPE) {
//                continue;
//            }
//            String terminalId = transRecordResponseBO.getTerminalId();
//            GasStationPO gasStationPO = gasStationMapper.qryByTerminalId(terminalId);
//            if (gasStationPO != null) {
//                transRecordResponseBO.setOil_station(gasStationPO.getMerchName());
//                transRecordResponseBO.setOil_station_address(gasStationPO.getAddress());
//            } else {
//                transRecordResponseBO.setOil_station("N/A");
//                transRecordResponseBO.setOil_station_address("N/A");
//            }
//        }
//
//        return list;
//    }
//
//    /**
//     * 消费订单
//     */
//    @Override
//    public List<ConsOrderResponseBO> findConsOrderList(HttpServletRequest request) throws Exception {
//        JSONObject jsonObject = this.parseRequest(request);
//        String oil_type = jsonObject.getString("oil_type");
//        int page_num = Integer.valueOf(jsonObject.getString("page_num"));
//        int limit = Integer.valueOf(jsonObject.getString("page_size"));
//        int offset = limit * (page_num - 1);
//        /* 获取卡号 */
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        /*
//         * 查询未打印发票的消费订单
//         */
//        List<ConsOrderResponseBO> list = weChatMapper.findConsOrderList(oil_type, cardId, offset, limit);
//
//        return list;
//    }
//
//    /**
//     * 申请发票
//     *
//     * @param request
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public Map<String, String> insertInvoices(HttpServletRequest request) throws Exception {
//        Map<String, String> resultMap = new HashMap<String, String>(2);
//        JSONObject jsonObject = this.parseRequest(request);
//        InvoicesRequestBO invoicesRequestBO = JSONObject.toJavaObject(jsonObject, InvoicesRequestBO.class);
//
//        // 重复开票
//        InvoiceRecordPO queryDO = invoiceRecordMapper.qryByBillOrderNo(invoicesRequestBO.getOrder_id());
//        if (!ObjectUtils.isEmpty(queryDO)) {
//            LOGGER.error("申请发票，发票已申请，重复申请发票，请求数据 {}", invoicesRequestBO);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "请勿重新开票");
//            return resultMap;
//        }
//
//        BillConsumePO billConsumePO = billConsumeMapper.qry(invoicesRequestBO.getOrder_id());
//        if (ObjectUtils.isEmpty(billConsumePO)) {
//            LOGGER.error("申请发票，订单信息查询失败，请求数据 {}", invoicesRequestBO);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "系统错误");
//            return resultMap;
//        }
//
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        OilCardPO oilCardPO = oilCardMapper.selectByUid(esUserPO.getUid());
//        if (ObjectUtils.isEmpty(oilCardPO)) {
//            LOGGER.error("申请发票，卡信息查询失败，请求数据 {}", invoicesRequestBO);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "系统错误");
//            return resultMap;
//        }
//
//        String orderNo = OrderNoUtil.generatorOrderNo(OrderNoConstant.PREFIX_INVOICE);
//        InvoiceRecordPO recordPO = new InvoiceRecordPO();
//        recordPO.setOrderNo(orderNo);
//        recordPO.setUid(esUserPO.getUid());
//        recordPO.setTitle(invoicesRequestBO.getInvoice_title());
//        recordPO.setContent(invoicesRequestBO.getInvoice_content());
//        recordPO.setAcceptEmail(invoicesRequestBO.getInvoice_receive_email());
//        recordPO.setTaxNo(invoicesRequestBO.getInvoic_tax_no());
//        recordPO.setBillOrderNo(invoicesRequestBO.getOrder_id());
//        recordPO.setCardId(oilCardPO.getCardId());
//        recordPO.setAmount(billConsumePO.getConsumeAmount());
//        recordPO.setType(BusinessConstant.INVOICE_TYPE.GENERAL);
//        recordPO.setCategory(BusinessConstant.INVOICE_CATEGORY.ELECTRON);
//        recordPO.setState(BusinessConstant.INVOICE_STATE.DONE);
//        recordPO.setBankName(invoicesRequestBO.getBankName());
//        recordPO.setBankNo(invoicesRequestBO.getBankAccount());
//        recordPO.setAcceptMobile(invoicesRequestBO.getBuyerMobile());
//        recordPO.setAcceptAddress(invoicesRequestBO.getBuyerAddress());
//
//        String pdfPath = xlInvoiceServlet.applyPrintInvoice(recordPO, billConsumePO, oilCardPO);
//        if (ObjectUtils.isEmpty(pdfPath)) {
//            LOGGER.error("申请发票，发票申请失败，请求数据 {}", invoicesRequestBO);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "发票申请失败，稍后重试");
//            return resultMap;
//        }
//
//        String imageUrl = xlInvoiceServlet.getInvoiceImageUrl(orderNo, pdfPath);
//        recordPO.setPdfPath(pdfPath);
//        recordPO.setImagePath(imageUrl);
//        recordPO.setDoneTime(new Date());
//        recordPO.setGmtCreate(new Date());
//        recordPO.setGmtModified(new Date());
//
//        int cnt = invoiceRecordMapper.save(recordPO);
//        if (1 != cnt) {
//            LOGGER.error("申请发票，保存发票数据失败，请求数据 {}", invoicesRequestBO);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "系统错误");
//            return resultMap;
//        }
//
//        // 更新订单状态
//        BillConsumePO updateBill = new BillConsumePO();
//        updateBill.setOrderId(billConsumePO.getOrderId());
//        updateBill.setPrintInvoiceState(BusinessConstant.ORDER_PRINT_INVOICE_STATE.DONE);
//        updateBill.setModifyDate(new Date());
//        cnt = billConsumeMapper.update(updateBill);
//        if (1 != cnt) {
//            LOGGER.error("申请发票，更新订单数据数据失败，请求数据 {}", invoicesRequestBO);
//        }
//        resultMap.put("result", "SUCCESS");
//        resultMap.put("message", "申请发票成功");
//        try {
//            SampleMail.send(recordPO);
//        } catch (Exception ex) {
//            LOGGER.warn("申请发票，发送邮件异常 {}", ex);
//        }
//        sendToUserWechatAfterInvoicePrint(billConsumePO, recordPO.getTitle());
//        return resultMap;
//    }
//
//    /**
//     * 发票冲红
//     *
//     * @param request
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public Map<String, String> writeOffInvoice(HttpServletRequest request) throws Exception {
//        Map<String, String> resultMap = new HashMap<>(2);
//        JSONObject jsonObject = this.parseRequest(request);
//        InvoiceWriteOffRequestBO invoicesWriteOffRequestBO = JSONObject.toJavaObject(jsonObject, InvoiceWriteOffRequestBO.class);
//        //查询是否有开票记录
//        InvoiceRecordPO invoiceRecordPO = invoiceRecordMapper.queryByInvoiceId(invoicesWriteOffRequestBO.getInvoice_id());
//        if (ObjectUtils.isEmpty(invoiceRecordPO)) {
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "无开票记录");
//            return resultMap;
//        }
//        //该消费订单号已有冲红发票
//        List<InvoiceRecordPO> redList = invoiceRecordMapper.selectByBillOrderNoAndState(invoiceRecordPO.getBillOrderNo(), BusinessConstant.INVOICE_STATE.WRITEOFF);
//        if (!ObjectUtils.isEmpty(redList)) {
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "发票冲红失败，该订单号已存在冲红");
//            return resultMap;
//        }
//
//        //调发票冲红接口
//        String pdfurl = xlInvoiceServlet.writeOffInvoice(invoiceRecordPO);
//        if (pdfurl == null) {
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "发票冲红失败");
//            return resultMap;
//        }
//
//        // 更新订单状态
//        BillConsumePO updateBill = BillConsumePO.builder().orderId(invoiceRecordPO.getBillOrderNo()).printInvoiceState(BusinessConstant.ORDER_PRINT_INVOICE_STATE.UNDONE)
//                .modifyDate(new Date()).build();
//        int cnt = billConsumeMapper.update(updateBill);
//        if (1 != cnt) {
//            LOGGER.error("申请发票，更新订单数据数据失败，请求数据 {}", updateBill);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "发票冲红失败");
//            return resultMap;
//        }
//        //更新发票状态
//        InvoiceRecordPO updateInvoiceRecord = InvoiceRecordPO.builder().orderNo(invoiceRecordPO.getOrderNo())
//                .state(BusinessConstant.INVOICE_STATE.WRITEOFF).redPdfPath(pdfurl)
//                .gmtModified(new Date()).build();
//        cnt = invoiceRecordMapper.update(updateInvoiceRecord);
//        if (1 != cnt) {
//            LOGGER.error("发票冲红，更新发票数据失败，请求数据 {}", updateInvoiceRecord);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "发票冲红失败");
//            return resultMap;
//        }
//
//        resultMap.put("result", "SUCCESS");
//        resultMap.put("message", "发票冲红成功");
//        return resultMap;
//    }
//
//    /**
//     * 开票历史
//     */
//    @Override
//    public List<InvoiceHistoryResponseBO> findInvoices(HttpServletRequest request) throws Exception {
//        JSONObject jsonObject = this.parseRequest(request);
//        int page_num = Integer.valueOf(jsonObject.getString("page_num"));
//        int limit = Integer.valueOf(jsonObject.getString("page_size"));
//        int offset = limit * (page_num - 1);
//        /* 获取卡号 */
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        List<InvoiceHistoryResponseBO> list = weChatMapper.findInvoices(cardId, offset, limit);
//        for (InvoiceHistoryResponseBO invoiceHistoryResponseBO : list) {
//            List<InvoiceRecordPO> redList = invoiceRecordMapper.selectByBillOrderNoAndState(invoiceHistoryResponseBO.getOrder_id(), 2);
//            if (ObjectUtils.isEmpty(redList)) {
//                invoiceHistoryResponseBO.setAllowRed("1");
//            } else {
//                invoiceHistoryResponseBO.setAllowRed("0");
//            }
//        }
//        return list;
//    }
//
//    /**
//     * 重新发送发票
//     */
//    @Override
//    public Map<String, String> sendInvoices(HttpServletRequest request) throws Exception {
//        JSONObject jsonObject = this.parseRequest(request);
//        String invoice_id = jsonObject.getString("invoice_id");// 发票编号
//        String invoice_receive_email = jsonObject.getString("invoice_receive_email");// 发票接受邮箱地址
//        InvoiceRecordPO invoice = invoiceRecordMapper.qry(invoice_id);
//        Map<String, String> resultMap = new HashMap<String, String>();
//        if (invoice == null) {
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "查询不到已开票记录");
//            return resultMap;
//        }
//        invoice.setAcceptEmail(invoice_receive_email);
//        try {
//            SampleMail.send(invoice);
//        } catch (Exception ex) {
//            LOGGER.error("发票申请，发送邮件异常，发票内容 {}", invoice, ex);
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "发送邮件失败");
//            return resultMap;
//        }
//        resultMap.put("result", "SUCCESS");
//        resultMap.put("message", "发送发票邮件成功");
//        return resultMap;
//    }
//
//    /**
//     * 会员中心
//     */
//    @Override
//    public MemberCenterResponseBO findMember(HttpServletRequest request) throws Exception {
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        // 查询卡余额
//        BigDecimal balance = xlCoreService.qryOilCardBalance_card(cardId);
//        MemberCenterResponseBO member = new MemberCenterResponseBO();
//        member.setUser_name(esUserPO.getRealname());
//        member.setUser_mobile(esUserPO.getMobile());
//        member.setHead_image(esUserPO.getHeadImage());
//        member.setBalance(balance);
//        return member;
//    }
//
//    /**
//     * 微信支付查询余额
//     */
//    @Override
//    public BalanceResponseBO findbalance(HttpServletRequest request) throws Exception {
//        /* 获取卡号 */
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        List<BillResponseBO> billList = weChatMapper.findbalance(cardId);
//        BalanceResponseBO balanceResponseBO = new BalanceResponseBO();
//        // 查询卡余额
//        BigDecimal balance = xlCoreService.qryOilCardBalance_card(cardId);
//        balanceResponseBO.setAccount_balance(balance);
//        /*
//         * if(CollectionUtils.isEmpty(billList)) { return balanceResponseBO; }
//         */
//        balanceResponseBO.setOrder_list(billList);
//        return balanceResponseBO;
//    }
//
//    /**
//     * 充值展示
//     */
//    @Override
//    public RechargeResponseBO findRecharge(HttpServletRequest request) throws Exception {
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        //String cardId = "7716170700000080";
//        // 查询该用户的优惠券信息
//		/*OilCouponPutPO couponPutPO = OilCouponPutPO.builder()
//				.cardNo(cardId)
//				.validTime(new Date())
//				.invalidTime(new Date()).build();
//		List<OilCouponPutPO> oilCouponPutList = oilCouponPutMapper.findOilCouponPutList(couponPutPO);
//		List<OilCouponPutBO> oilCouponPutBOList =new ArrayList<>();
//		if (!CollectionUtils.isEmpty(oilCouponPutList)) {
//			oilCouponPutList.forEach( oilcouponPutPO -> {
//			OilCouponPO oilCouponPO =	oilCouponPoMapper.findOilCouponPO(oilcouponPutPO.getCouponId());
//			OilCouponPutBO oilCouponPutBO = new OilCouponPutBO();
//			oilCouponPutBO.setCouponId(oilcouponPutPO.getId());
//			oilCouponPutBO.setDiscountAmount(oilCouponPO.getDiscountAmount());
//			oilCouponPutBO.setInvalidTime(new SimpleDateFormat("yyyy-MM-dd").format(oilcouponPutPO.getInvalidTime()));
//			oilCouponPutBO.setValidTime(new SimpleDateFormat("yyyy-MM-dd").format(oilcouponPutPO.getValidTime()));
//			oilCouponPutBOList.add(oilCouponPutBO);
//			});
//
//		}*/
//        //充值金额
//        List<RechargeDetailsBO> rechargeList = weChatMapper.rechargeList();
//        RechargeResponseBO rechargeResponseBO = new RechargeResponseBO();
//        rechargeResponseBO.setUser_mobile(esUserPO.getMobile());
//        rechargeResponseBO.setOil_card_id(cardId);
//        if (CollectionUtils.isEmpty(rechargeList)) {
//            return rechargeResponseBO;
//        }
//        rechargeResponseBO.setRecharge_price_list(rechargeList);
//		/*rechargeResponseBO.setOilCouponPutBOList(oilCouponPutBOList);
//		rechargeResponseBO.setCouponNum(oilCouponPutBOList.size());*/
//        return rechargeResponseBO;
//    }
//
//    /**
//     * 微信统一下单
//     *
//     * @param request
//     * @param response
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public String wechatUnifiedOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        String errJson = "{\"msg\":\"调用微信充值失败\"}";
//
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String jsonStr = RequestUtil.getString(request);
//        if (StringUtils.isEmpty(jsonStr)) {
//            LOGGER.error("微信会员卡，发起微信充值，失败，请求内容为空");
//            return errJson;
//        }
//        LOGGER.info("微信会员卡，发起微信充值，请求内容={}，用户={}", jsonStr, esUserPO);
//        BillRechargePO billRechargePO = null;
//        Map<String, Object> resultMap = findOilCouponPO(jsonStr, esUserPO);
//        if ("FAIl".equals(resultMap.get("result"))) {
//            return (String) resultMap.get("message");
//        } else if ("SUCCESS".equals(resultMap.get("result"))) {
//            OilCouponPO oilCouponPO = (OilCouponPO) resultMap.get("message");
//            billRechargePO = saveRecharge(jsonStr, esUserPO, oilCouponPO);
//        } else {
//            billRechargePO = saveRecharge(jsonStr, esUserPO, null);
//        }
//
//
//        if (null == billRechargePO) {
//            return errJson;
//        }
//
//        /*------1.获取参数信息------- */
//        // 商户订单号
//        String out_trade_no = billRechargePO.getOrderId();
//        // 价格
//        String money = String.valueOf(billRechargePO.getCutPayment());
//        // 金额转化为分为单位
//        String finalmoney = EStationUtils.getMoney(money);
//        String openid = esUserPO.getWechatOpenid();
//        //String openid = "ohv6qs8oKuc0xAyBpVxgsUBehfZA";
//        /*------3.生成预支付订单需要的的package数据------- */
//        // 随机数
//        String nonce_str = WechatUtil.getMessageDigest(String.valueOf(new Random().nextInt(10000)).getBytes());
//        // 订单生成的机器 IP
//        String spbill_create_ip = request.getRemoteAddr();
//        SortedMap<String, String> packageParams = new TreeMap<String, String>();
//        packageParams.put("appid", SysParamsUtil.getSysParams(SysParamConstant.WECHAT_GZHID));
//        packageParams.put("mch_id", SysParamsUtil.getSysParams(SysParamConstant.WECHAT_SHHID));
//        packageParams.put("nonce_str", nonce_str);
//        packageParams.put("body", "费用");
//        packageParams.put("out_trade_no", out_trade_no);
//        packageParams.put("total_fee", finalmoney);
//        packageParams.put("spbill_create_ip", spbill_create_ip);
//        // 这里notify_url是 微信处理完支付后的回调的应用系统接口url。
//        packageParams.put("notify_url", SysParamsUtil.getSysParams(SysParamConstant.WECHAT_NOTIFY_URL));
//        // 交易类型 ：jsapi代表微信公众号支付
//        packageParams.put("trade_type", "JSAPI");
//        packageParams.put("openid", openid);
//
//        if (LOGGER.isDebugEnabled()) {
//            LOGGER.debug("微信会员卡，发起微信充值，生成package数据={}，请求内容={}，用户={}", packageParams, jsonStr, esUserPO);
//        }
//
//        /*------4.根据package数据生成预支付订单号的签名sign------- */
//        String sign = WxPayUtil.createSign(packageParams, SysParamsUtil.getSysParams(SysParamConstant.WECHAT_SHHKEY));
//
//        /*------5.生成需要提交给统一支付接口https://api.mch.weixin.qq.com/pay/unifiedorder 的xml数据-------*/
//        String xml = "<xml>" + "<appid>" + SysParamsUtil.getSysParams(SysParamConstant.WECHAT_GZHID) + "</appid>"
//                + "<mch_id>" + SysParamsUtil.getSysParams(SysParamConstant.WECHAT_SHHID) + "</mch_id>" + "<nonce_str>"
//                + nonce_str + "</nonce_str>" + "<sign>" + sign + "</sign>" + "<body><![CDATA[" + "费用" + "]]></body>"
//                + "<out_trade_no>" + out_trade_no + "</out_trade_no>" + "<total_fee>" + finalmoney + "</total_fee>"
//                + "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>" + "<notify_url>"
//                + SysParamsUtil.getSysParams(SysParamConstant.WECHAT_NOTIFY_URL) + "</notify_url>" + "<trade_type>"
//                + "JSAPI" + "</trade_type>" + "<openid>" + openid + "</openid>" + "</xml>";
//
//        if (LOGGER.isDebugEnabled()) {
//            LOGGER.debug("微信会员卡，发起微信充值，微信统一下单数据={}，请求内容={}，用户={}", xml, jsonStr, /*esUserPO*/null);
//        }
//
//        /*------6.调用统一支付接口https://api.mch.weixin.qq.com/pay/unifiedorder 生产预支付订单----------*/
//        String createOrderURL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//        String prepay_id;
//        prepay_id = GetWxOrderno.getPayNo(createOrderURL, xml);
//        if (StringUtils.isEmpty(prepay_id)) {
//            return errJson;
//        }
//        /*------7.将预支付订单的id和其他信息生成签名并一起返回到jsp页面 ------- */
//        nonce_str = WechatUtil.getMessageDigest(String.valueOf(new Random().nextInt(10000)).getBytes());
//        SortedMap<String, String> finalpackage = new TreeMap<String, String>();
//        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
//        String packages = "prepay_id=" + prepay_id;
//        finalpackage.put("appId", SysParamsUtil.getSysParams(SysParamConstant.WECHAT_GZHID));
//        finalpackage.put("timeStamp", timestamp);
//        finalpackage.put("nonceStr", nonce_str);
//        finalpackage.put("package", packages);
//        finalpackage.put("signType", "MD5");
//        String finalsign = WxPayUtil.createSign(finalpackage,
//                SysParamsUtil.getSysParams(SysParamConstant.WECHAT_SHHKEY));
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("appid", SysParamsUtil.getSysParams(SysParamConstant.WECHAT_GZHID));
//        jsonObject.put("timeStamp", timestamp);
//        jsonObject.put("nonceStr", nonce_str);
//        jsonObject.put("packageValue", packages);
//        jsonObject.put("paySign", finalsign);
//        jsonObject.put("success", "ok");
//
//        return jsonObject.toJSONString();
//    }
//
//    /**
//     * 查询优惠券信息
//     *
//     * @param jsonStr
//     * @param esUserPO
//     * @return
//     * @throws Exception Map<String,Object>
//     * @throws
//     * @Title: findOilCouponPO
//     * @Description:
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public Map<String, Object> findOilCouponPO(String jsonStr, EsUserPO esUserPO) throws Exception {
//        Map<String, Object> resultMap = new HashMap<String, Object>();
//        InitiatingRechargeRequestBO initiatingRechargeRequestBO = JSON.parseObject(jsonStr,
//                InitiatingRechargeRequestBO.class);
//        if (new BigDecimal(initiatingRechargeRequestBO.getRecharge_price_total().intValue()).compareTo(initiatingRechargeRequestBO.getRecharge_price_total()) != 0) {
//            String rechargePriceTotal = initiatingRechargeRequestBO.getRecharge_price_total().toString();
//            int indexOf = rechargePriceTotal.indexOf(".");
//            int dcimalDigits = rechargePriceTotal.length() - 1 - indexOf;
//            if (dcimalDigits > 2) {
//                LOGGER.error("微信会员卡，发起微信充值，失败，充值金额只能保留两位小数，请求内容={}", initiatingRechargeRequestBO.getRecharge_price_total());
//                resultMap.put("result", "FAIl");
//                resultMap.put("message", "{\"msg\":\"充值金额只能保留两位小数\"}");
//                return resultMap;
//            }
//
//        }
//
//        if (initiatingRechargeRequestBO.getRecharge_price_total().compareTo(new BigDecimal(SysParamsUtil.getSysParams(SysParamConstant.RECHARGE_CEILING))) == 1) {
//            LOGGER.error("微信会员卡，发起微信充值，失败，充值金额大于2000，请求内容={}", initiatingRechargeRequestBO.getRecharge_price_total());
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "{\"msg\":\"充值上限为2000元\"}");
//            return resultMap;
//        }
//        if (initiatingRechargeRequestBO.getRecharge_price_total().compareTo(new BigDecimal(SysParamsUtil.getSysParams(SysParamConstant.RECHARGE_THRESHOLD))) == -1) {
//            LOGGER.error("微信会员卡，发起微信充值，失败，充值金额小于10，请求内容={}", initiatingRechargeRequestBO.getRecharge_price_total());
//            resultMap.put("result", "FAIl");
//            resultMap.put("message", "{\"msg\":\"充值下限为10元\"}");
//            return resultMap;
//        }
//        /**
//         * 判断是否输入兑换码
//         */
//        if (StringUtils.isNotEmpty(initiatingRechargeRequestBO.getConversionCode())) {
//            //校验兑换码的合法性
//            Boolean checkResult = CdkeyUtil.checkCdkey(initiatingRechargeRequestBO.getConversionCode(), SysParamsUtil.getSysParams(SysParamConstant.E_HIGH_SPEED_COUPON_FACTOR), StringUtils.leftPad(SysParamsUtil.getSysParams(SysParamConstant.E_HIGH_SPEED_ACTIVITY_ID), 4, "0"));
//            if (checkResult) {
//                //根据cardId、兑换码conversionCode查询是否存在此优惠券
//                OilCouponPutPO newOilCouponPutPO = OilCouponPutPO.builder().mobile(esUserPO.getMobile()).cdkey(initiatingRechargeRequestBO.getConversionCode()).build();
//                OilCouponPutPO oilCouponPutPO = oilCouponPutMapper.queryOilCouponPutPO(newOilCouponPutPO);
//                if (oilCouponPutPO == null) {
//                    LOGGER.error("微信会员卡，发起微信充值，失败，该用户兑换码不存在，请求内容={} ，用户={}", oilCouponPutPO, esUserPO);
//                    resultMap.put("result", "FAIl");
//                    resultMap.put("message", "{\"msg\":\"支付失败：您输入的兑换码信息不正确，请核实后重试。\"}");
//                    return resultMap;
//                }
//                if (BusinessConstant.COUPON_STATUS.USED.equals(oilCouponPutPO.getCouponStatus())) {
//                    LOGGER.error("微信会员卡，发起微信充值，失败，该用户兑换码已使用，请求内容={} ，用户={}", oilCouponPutPO, esUserPO);
//                    resultMap.put("result", "FAIl");
//                    resultMap.put("message", "{\"msg\":\"兑换券已使用\"}");
//                    return resultMap;
//                }
//                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//                //当前日期
//                String nowdayTime = formatter.format(new Date());
//                Date nowDate = formatter.parse(nowdayTime);
//                //生效日期
//                String validTime = formatter.format(oilCouponPutPO.getValidTime());
//                Date validDate = formatter.parse(validTime);
//                //失效日期
//                String invalidTime = formatter.format(oilCouponPutPO.getInvalidTime());
//                Date invalidDate = formatter.parse(invalidTime);
//                if (nowDate.getTime() < validDate.getTime()) {
//                    LOGGER.error("微信会员卡，发起微信充值，失败，该用户兑换码未到生效日期，当前日期={} ，生效日期={}", nowdayTime, validTime);
//                    resultMap.put("result", "FAIl");
//                    resultMap.put("message", "{\"msg\":\"兑换码未到生效日期\"}");
//                    return resultMap;
//                }
//                if (nowDate.getTime() > invalidDate.getTime()) {
//                    LOGGER.error("微信会员卡，发起微信充值，失败，该用户兑换码已失效，当前日期={} ，失效日期={}", nowdayTime, invalidTime);
//                    resultMap.put("result", "FAIl");
//                    resultMap.put("message", "{\"msg\":\"兑换码已失效\"}");
//                    return resultMap;
//                }
//                //根据优惠券投放信息查询优惠券具体信息
//                OilCouponPO oilCouponPO = oilCouponPoMapper.findOilCouponPO(oilCouponPutPO.getCouponId());
//                if (oilCouponPO == null) {
//                    LOGGER.error("微信会员卡，发起微信充值，失败，该用户兑换码不存在，请求内容={} ，用户={}", oilCouponPutPO, esUserPO);
//                    resultMap.put("result", "FAIl");
//                    resultMap.put("message", "{\"msg\":\"支付失败：您输入的兑换码信息不正确，请核实后重试。\"}");
//                    return resultMap;
//                }
//                //判断用户兑换券金额是否大于等于充值金额
//                if (oilCouponPO.getDiscountAmount().compareTo(initiatingRechargeRequestBO.getRecharge_price_total()) != -1) {
//                    LOGGER.error("微信会员卡，发起微信充值，失败，用户兑换金额不得大于或等于充值金额，请求内容={} ，兑换券={}", initiatingRechargeRequestBO, oilCouponPO);
//                    resultMap.put("result", "FAIl");
//                    resultMap.put("message", "{\"msg\":\"兑换金额不得大于或等于充值金额\"}");
//                    return resultMap;
//                }
//                resultMap.put("result", "SUCCESS");
//                resultMap.put("message", oilCouponPO);
//                return resultMap;
//            } else {
//                LOGGER.error("微信会员卡，发起微信充值，失败，用户兑换码输入不合法，请求内容={}", initiatingRechargeRequestBO);
//                resultMap.put("result", "FAIl");
//                resultMap.put("message", "{\"msg\":\"兑换码输入不合法，请核对后重试！\"}");
//                return resultMap;
//            }
//
//        } else {
//            resultMap.put("result", "success");
//            resultMap.put("message", null);
//            return resultMap;
//        }
//    }
//
//    /**
//     * 保存充值订单信息
//     *
//     * @param jsonStr
//     * @param esUserPO
//     * @return
//     * @throws Exception
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public BillRechargePO saveRecharge(String jsonStr, EsUserPO esUserPO, OilCouponPO oilCouponPO) throws Exception {
//        InitiatingRechargeRequestBO initiatingRechargeRequestBO = JSON.parseObject(jsonStr,
//                InitiatingRechargeRequestBO.class);
//
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        if (StringUtils.isEmpty(cardId)) {
//            LOGGER.error("微信会员卡，发起微信充值，失败，卡号查询为空，请求内容={} ，用户={}", jsonStr, esUserPO);
//            return null;
//        }
//        /*
//         * 生成订订单并保存，此时为未支付状态
//         */
//        String outOrderNo = OrderNoUtil.buildOrderNo(OrderNoUtil.OrderType.BILL_RECHARGE);
//        BillRechargePO billRecharge = new BillRechargePO();
//        billRecharge.setOrderId(outOrderNo);
//        billRecharge.setCardId(cardId);
//        billRecharge.setOrderPayment(BusinessConstant.ORDER_PAYMENT.WECHAT);
//        billRecharge.setStatus(BusinessConstant.ORDER_STATE.ORDER_CREATE);
//        billRecharge.setAmount(initiatingRechargeRequestBO.getRecharge_price_base());
//        billRecharge.setRechargeAmount(initiatingRechargeRequestBO.getRecharge_price_total());
//        billRecharge.setGmtCreate(new Date());
//        billRecharge.setGmtModified(new Date());
//        /**
//         * 判断是否输入兑换码
//         */
//        if (oilCouponPO != null) {
//            BigDecimal cutPayment = initiatingRechargeRequestBO.getRecharge_price_total().subtract(oilCouponPO.getDiscountAmount());
//            billRecharge.setCutPayment(cutPayment);
//            billRecharge.setDeductibleAmount(oilCouponPO.getDiscountAmount());
//            billRecharge.setCdkey(initiatingRechargeRequestBO.getConversionCode());
//        } else {
//            billRecharge.setCutPayment(initiatingRechargeRequestBO.getRecharge_price_total());
//        }
//
//        int count = billRechargeMapper.save(billRecharge);
//        if (count != 1) {
//            LOGGER.error("微信会员卡，发起微信充值，失败，保存充值订单表失败，请求内容={} ，用户={}", jsonStr, esUserPO);
//            return null;
//        }
//        return billRecharge;
//    }
//
//    /**
//     * 微信支付充值
//     *
//     * @param xmlStr
//     * @throws Exception
//     */
//    @Override
//    public void wxPayRecharge(String xmlStr) throws Exception {
//        LOGGER.info("微信加油卡，微信支付充值，请求内容={}", xmlStr);
//        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//        dbf.setExpandEntityReferences(false);
//        Document document = new SAXReader().read(new ByteArrayInputStream(xmlStr.getBytes("utf-8")));
//        String out_trade_no = document.selectSingleNode("/xml/out_trade_no").getText();
//        BillRechargePO billRecharge = billRechargeMapper.qry(out_trade_no);
//        if (null == billRecharge) {
//            LOGGER.error("微信加油卡，微信支付充值，订单信息查询失败，请求内容={}", xmlStr);
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，失败，订单信息查询失败", xmlStr);
//            return;
//        }
//
//        // 不是下单状态的，不处理
//        if (!StringUtils.equals(BusinessConstant.ORDER_STATE.ORDER_CREATE, billRecharge.getStatus())) {
//            LOGGER.error("微信加油卡，微信支付充值，订单状态异常，不作处理，当前订单信息={}，请求内容={}", billRecharge, xmlStr);
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，订单状态异常，不作处理", xmlStr);
//            return;
//        }
//
//        // 校验签名
//        String sign = document.selectSingleNode("/xml/sign").getText();
//        SortedMap<String, String> smap = WxPayUtil.dom4jXMLParse(xmlStr);
//        String createsign = WxPayUtil.createSign(smap, SysParamsUtil.getSysParams(SysParamConstant.WECHAT_SHHKEY));
//        if (!StringUtils.equals(sign, createsign)) {
//            LOGGER.error("微信加油卡，微信支付充值，签名校验失败，生成签名={}，回调签名={}", createsign, sign);
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，签名校验失败", sign);
//            billRecharge.setStatus(BusinessConstant.ORDER_STATE.RECHARGE_PAY_FAILED);
//            updateRechargeBill(billRecharge);
//            return;
//        }
//        String transaction_id = document.selectSingleNode("/xml/transaction_id").getText();
//        billRecharge.setPayInOrderNo(transaction_id);
//        String time_end = document.selectSingleNode("/xml/time_end").getText();
//        billRecharge.setOrderPayTime(DateUtil.str2date(time_end, DateUtil.DATE_FORMATTER1));
//        String result_code = document.selectSingleNode("/xml/result_code").getText();
//        // 判断支付结果
//        // 支付失败
//        if (StringUtils.equals("FAIL", result_code)) {
//            LOGGER.error("微信加油卡，微信支付充值，支付失败，请求内容={}", xmlStr);
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，失败，支付失败", xmlStr);
//            billRecharge.setStatus(BusinessConstant.ORDER_STATE.RECHARGE_PAY_FAILED);
//            updateRechargeBill(billRecharge);
//            return;
//        }
//
//        // 支付成功
//        LOGGER.info("微信加油卡，微信支付充值，支付成功，请求内容={}", xmlStr);
//        billRecharge.setStatus(BusinessConstant.ORDER_STATE.RECHARGE_PAY_SUCCESS);
//        updateRechargeBill(billRecharge);
//        /**
//         * 更新优惠券状态
//         */
//        if (StringUtils.isNotEmpty(billRecharge.getCdkey())) {
//            updateOilCouponPut(billRecharge);
//        }
//        // 发起pos充值
//        try {
//            // 充值成功
//            String applyNo = OrderNoUtil.buildTransId();
//            billRecharge.setXlcoreOutOrderNo(applyNo);
//            Msg3123 msg3123 = xlCoreService.posRecharge(billRecharge);
//            if (!StringUtils.equals(msg3123.getResponseCode(), PosResponseCodeEnum.交易成功.code)) {
//                LOGGER.error("微信加油卡，微信支付充值，发起pos充值失败 错误码 {} 描述 {}，请求内容={]", msg3123.getResponseCode(),
//                        PosResponseCodeEnum.msg(msg3123.getResponseCode()), xmlStr);
//                exceptionSevice.saveRecordNow(this.getClass(),
//                        "微信加油卡，微信支付充值，发起pos充值失败 错误码：" + msg3123.getResponseCode(), xmlStr);
//                billRecharge.setStatus(BusinessConstant.ORDER_STATE.RECHARGE_FAILED);
//                updateRechargeBill(billRecharge);
//            }
//
//            LOGGER.info("微信加油卡，微信支付充值，充值成功，充值信息={}，请求内容={}", msg3123, xmlStr);
//            billRecharge.setXlcoreInOrderNo(msg3123.getSaleSerialNo());
//            billRecharge.setStatus(BusinessConstant.ORDER_STATE.RECHARGE_SUCCESS);
//            billRecharge.setOrderRechargeTime(new Date());
//            updateRechargeBill(billRecharge);
//        } catch (Exception e) {
//            // 充值失败
//            LOGGER.error("微信加油卡，微信支付充值，发起pos充值失败 {}，请求内容={}", e.getMessage(), xmlStr);
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，发起pos充值失败" + e.getMessage(), xmlStr);
//            billRecharge.setStatus(BusinessConstant.ORDER_STATE.RECHARGE_FAILED);
//            updateRechargeBill(billRecharge);
//        }
//    }
//
//    /**
//     * 更新充值账单表
//     *
//     * @param billRechargePO
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public void updateRechargeBill(BillRechargePO billRechargePO) {
//        billRechargePO.setGmtModified(new Date());
//        int count = billRechargeMapper.update(billRechargePO);
//        if (1 != count) {
//            LOGGER.error("微信加油卡，微信支付充值，更新充值账单表失败，更新内容={}", billRechargePO);
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，更新充值账单表失败", billRechargePO.toString());
//        }
//        LOGGER.info("微信加油卡，微信支付充值，更新充值账单表成功，更新内容={}", billRechargePO);
//    }
//
//    /**
//     * @param billRechargePO void
//     * @throws
//     * @Title: updateOilCouponPut
//     * @Description: 更新优惠券投放信息
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public void updateOilCouponPut(BillRechargePO billRechargePO) {
//        //根据手机号与兑换码确定一条优惠券信息
//        String mobile = esUserMapper.findMobileByUid(billRechargePO.getCardId());
//        OilCouponPutPO newOilCouponPutPO = OilCouponPutPO.builder().mobile(mobile).cdkey(billRechargePO.getCdkey()).orderId(billRechargePO.getOrderId()).useTime(new Date()).build();
//        OilCouponPutPO oilCouponPutPO = oilCouponPutMapper.queryOilCouponPutPO(newOilCouponPutPO);
//        if (oilCouponPutPO == null) {
//            LOGGER.error("微信加油卡，微信支付充值，查找优惠券投放信息失败，查找cdkey={}", billRechargePO.getCdkey());
//            exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，查找优惠券投放信息失败", billRechargePO.toString());
//        } else {
//            oilCouponPutPO.setCardNo(billRechargePO.getCardId());
//            oilCouponPutPO.setCouponStatus(BusinessConstant.COUPON_STATUS.USED);
//            oilCouponPutPO.setUseTime(new Date());
//            int count = oilCouponPutMapper.updateOilCouponPutPO(oilCouponPutPO);
//            if (1 != count) {
//                LOGGER.error("微信加油卡，微信支付充值，更新优惠券投放信息表失败，更新内容={}", oilCouponPutPO);
//                exceptionSevice.saveRecordNow(this.getClass(), "微信加油卡，微信支付充值，更新优惠券投放信息表失败", oilCouponPutPO.toString());
//            }
//            LOGGER.info("微信加油卡，微信支付充值，更新优惠券投放信息表成功，更新内容={}", oilCouponPutPO);
//        }
//    }
//
//    /**
//     * 适用加油站
//     */
//    @Override
//    public List<GasStationListResponseBO> findGasStationList(HttpServletRequest request) throws Exception {
//        /*
//         * EsUserPO esUserPO = WechatUtil.getSessionUser(request); String cardId =
//         * oilCardMapper.findCardIdByUid(esUserPO.getUid());
//         */
//        JSONObject jsonObject = this.parseRequest(request);
//        OilStationRequestBO oilStationRequestBO = JSONObject.toJavaObject(jsonObject, OilStationRequestBO.class);
//        List<GasStationListResponseBO> list = new ArrayList<>();
//        List<GasStationListResponseBO> midList = new ArrayList<>();
//        String sortParameter = oilStationRequestBO.getSortParameter();// 排序参数
//        int pageNum = oilStationRequestBO.getPage_Num();
//        int pageSize = oilStationRequestBO.getPage_Size();
//        String roadId = oilStationRequestBO.getRoadId();
//        /*
//         * if (StringUtils.isNotEmpty(cardId)) { list =
//         * oilStationMapper.findOilStationList(oilStationRequestBO); Double lng =
//         * oilStationRequestBO.getLng(); Double lat = oilStationRequestBO.getLat();
//         * list.forEach(gasStationListResponseBO -> { if (null ==
//         * gasStationListResponseBO.getGasStation_longitude() || null ==
//         * gasStationListResponseBO.getGasStation_latitude()) { return; } // 计算中心点到加油站距离
//         * double dist = MapDistanceUtil.getDistance( lng, lat,
//         * Double.valueOf(gasStationListResponseBO.getGasStation_longitude()),
//         * Double.valueOf(gasStationListResponseBO.getGasStation_latitude()));
//         * gasStationListResponseBO.setDist(dist); }); if (list.size() > 0) { for
//         * (GasStationListResponseBO gasStationListResponseBO : list) {
//         * gasStationListResponseBO.setLogurl(EStationUtils.getDownloadFileUrl(
//         * gasStationListResponseBO.getLogurl(),
//         * SysParamConstant.ESTATION_GASOLINEBRANDIMG_PATH));
//         * gasStationListResponseBO.setOilStationImage(EStationUtils.getDownloadFileUrl(
//         * gasStationListResponseBO.getOilStationImage(),
//         * SysParamConstant.ESTATION_GASOLINEBRANDIMG_PATH));
//         * gasStationListResponseBO.setGasStationOilPricePOs(gasStationOilPriceMapper.
//         * qry(gasStationListResponseBO.getGasStation_id()));
//         * gasStationListResponseBO.setOrderNum(String.valueOf(billConsumeMapper.
//         * countByTerminal(gasStationListResponseBO.getGasStation_id()))); } list =
//         * this.sortMethod(list,roadId, sortParameter,pageNum,pageSize);
//         *
//         * }
//         *
//         * }else {
//         */
//        list = oilStationMapper.findGasStationList(oilStationRequestBO);
//        Double lng = oilStationRequestBO.getLng();
//        Double lat = oilStationRequestBO.getLat();
//        list.forEach(gasStationListResponseBO -> {
//            if (null == gasStationListResponseBO.getGasStation_longitude()
//                    || null == gasStationListResponseBO.getGasStation_latitude()) {
//                return;
//            }
//            // 计算中心点到加油站距离
//            double dist = MapDistanceUtil.getDistance(lng, lat,
//                    Double.valueOf(gasStationListResponseBO.getGasStation_longitude()),
//                    Double.valueOf(gasStationListResponseBO.getGasStation_latitude()));
//            if (dist > 100) {
//                System.out.println(dist);
//                return;
//            }
//            gasStationListResponseBO.setDist(dist);
//            midList.add(gasStationListResponseBO);
//        });
//        if (midList.size() > 0) {
//            for (GasStationListResponseBO gasStationListResponseBO : midList) {
//                gasStationListResponseBO.setLogurl(EStationUtils.getDownloadFileUrl(
//                        gasStationListResponseBO.getLogurl(), SysParamConstant.ESTATION_GASOLINEBRANDIMG_PATH));
//				/*gasStationListResponseBO.setOilStationImage(
//						EStationUtils.getDownloadFileUrl(gasStationListResponseBO.getOilStationImage(),
//								SysParamConstant.ESTATION_GASOLINEBRANDIMG_PATH));*/
//                gasStationListResponseBO.setOilStationImage(gasStationListResponseBO.getOilStationImage());
//                gasStationListResponseBO.setGasStationOilPricePOs(
//                        gasStationOilPriceMapper.qry(gasStationListResponseBO.getGasStation_id()));
//                gasStationListResponseBO.setOrderNum(
//                        String.valueOf(billConsumeMapper.countByTerminal(gasStationListResponseBO.getGasStation_id())));
//            }
//            list = this.sortMethod(midList, roadId, sortParameter, pageNum, pageSize);
//        }
//        // }
//        return list;
//    }
//
//    /**
//     * 排序方法
//     *
//     * @param list
//     * @param sortParameter
//     * @return
//     */
//    public List<GasStationListResponseBO> sortMethod(List<GasStationListResponseBO> list, String roadId,
//                                                     String sortParameter, Integer pageNum, Integer pageSize) {
//        if ("0".equals(sortParameter) && list.size() > 0) {// 根据距离进行排序
//            Collections.sort(list, new Comparator<GasStationListResponseBO>() {
//                public int compare(GasStationListResponseBO o1, GasStationListResponseBO o2) {
//                    if (o1.getDist() < o2.getDist()) {
//                        return -1;
//                    }
//                    if (o1.getDist() == o2.getDist()) {
//                        return 0;
//                    }
//                    return 1;
//                }
//            });
//        } else if (list.size() > 0) {// 根据价格进行排序
//            Collections.sort(list, new Comparator<GasStationListResponseBO>() {
//                public int compare(GasStationListResponseBO o1, GasStationListResponseBO o2) {
//                    if (o1.getOilPrice().compareTo(o2.getOilPrice()) == -1) {
//                        return -1;
//                    }
//                    if (o1.getOilPrice().compareTo(o2.getOilPrice()) == 0) {
//                        return 0;
//                    }
//                    return 1;
//                }
//            });
//        }
//
//        int sum = list.size() % pageNum == 0 ? list.size() / pageNum : list.size() / pageNum + 1;
//        List<GasStationListResponseBO> gasList = new ArrayList<>();
//        if (pageSize < sum) {
//            for (int i = (pageNum * (pageSize - 1)); i < (pageNum * pageSize); i++) {
//                HighWayPO highWayPO = highWayMapper.findHighWayById(list.get(i).getGasStationRoadId());
//                if (StringUtils.isNotEmpty(highWayPO.getHighwayCode())) {
//                    list.get(i).setGasStation_road(highWayPO.getName() + "(" + highWayPO.getHighwayCode() + ")");
//                } else {
//                    list.get(i).setGasStation_road(highWayPO.getName());
//                }
//                gasList.add(list.get(i));
//            }
//        } else if (pageSize == sum) {
//            for (int i = (pageNum * (pageSize - 1)); i < list.size(); i++) {
//                HighWayPO highWayPO = highWayMapper.findHighWayById(list.get(i).getGasStationRoadId());
//                if (StringUtils.isNotEmpty(highWayPO.getHighwayCode())) {
//                    list.get(i).setGasStation_road(highWayPO.getName() + "(" + highWayPO.getHighwayCode() + ")");
//                } else {
//                    list.get(i).setGasStation_road(highWayPO.getName());
//                }
//                gasList.add(list.get(i));
//            }
//        }
//        return gasList;
//    }
//
//    /**
//     * 获取信联二维码
//     */
//    @Override
//    public String findOilQr(HttpServletRequest request) throws Exception {
//        EsUserPO esUserPO = WechatUtil.getSessionUser(request);
//        String cardId = oilCardMapper.findCardId(esUserPO.getUid());
//        String wechatOpenid = esUserPO.getWechatOpenid();
//        OilQrCodePO oilQrCodePO = new OilQrCodePO();
//        oilQrCodePO.setCardId(cardId);
//        oilQrCodePO.setQrMac(wechatOpenid);
//        String getQr = xlCoreService.getQr(oilQrCodePO);
//        if (StringUtils.isEmpty(getQr)) {
//            return null;
//        }
//        // 存储二维码信息
//        oilQrCodePO.setQrCode(getQr);
//        oilQrCodePO.setQrValidTime(new Date());
//        Date invalidTime = EStationUtils.getQrInvalidDate(new Date());
//        oilQrCodePO.setQrInvalidTime(invalidTime);
//        oilQrCodePO.setQrState(BusinessConstant.QR_CODE_STATE.MADE);
//        oilQrCodePO.setGmtCreate(new Date());
//        oilQrCodePO.setGmtModified(new Date());
//        oilQrCodePO.setQrChannel(BusinessConstant.CHANNEL.WECHAT);
//        int count = oilQrCodeMapper.save(oilQrCodePO);
//        if (1 != count) {
//            LOGGER.error("获取信联二维码，保存二维码表失败 {}", oilQrCodePO);
//            return null;
//        }
//        return getQr;
//    }
//
//    @SuppressWarnings("unused")
//    @Override
//    public String findInvoicesPdf(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        String orderNum = request.getParameter("orderNum");
//        LOGGER.info("获取订单号{}", orderNum);
//        if (StringUtils.isEmpty(orderNum)) {
//            LOGGER.error("获取订单号为空", orderNum);
//            return null;
//        }
//        InvoiceHistoryResponseBO invoiceHistoryResponseBO = weChatMapper.findInvoicesById(orderNum);
//        if (null == invoiceHistoryResponseBO) {
//            LOGGER.error("根据订单号查询订单信息失败，请求内容={}", orderNum);
//            return null;
//        }
//        ServletOutputStream out = null;
//        FileInputStream ips = null;
//        final float DEFAULT_DPI = 105;
//        try {
//            if (StringUtils.isEmpty(invoiceHistoryResponseBO.getPdfPath())) {
//                LOGGER.error("该笔订单发票pdf文件为空，请求内容={}", invoiceHistoryResponseBO);
//                return null;
//            }
//            URL url = new URL(invoiceHistoryResponseBO.getPdfPath());
//            URLConnection urlConnection = url.openConnection();
//            HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
//            httpURLConnection.setRequestMethod("POST");
//            httpURLConnection.setRequestProperty("Charset", "UTF-8");
//            httpURLConnection.connect();
//            int fileLength = httpURLConnection.getContentLength();
//            URLConnection con = url.openConnection();
//            BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
//            // 图像合并使用参数
//            int width = 0; // 总宽度
//            int[] singleImgRGB; // 保存一张图片中的RGB数据
//            int shiftHeight = 0;
//            BufferedImage imageResult = null;// 保存每张图片的像素值
//            // 利用PdfBox生成图像
//            PDDocument pdDocument = PDDocument.load(bin);
//            PDFRenderer renderer = new PDFRenderer(pdDocument);
//            // 循环每个页码
//            for (int i = 0, len = pdDocument.getNumberOfPages(); i < len; i++) {
//                BufferedImage image = renderer.renderImageWithDPI(i, DEFAULT_DPI, ImageType.RGB);
//                int imageHeight = image.getHeight();
//                int imageWidth = image.getWidth();
//                if (i == 0) {// 计算高度和偏移量
//                    width = imageWidth;// 使用第一张图片宽度;
//                    // 保存每页图片的像素值
//                    imageResult = new BufferedImage(width, imageHeight * len, BufferedImage.TYPE_INT_RGB);
//                } else {
//                    shiftHeight += imageHeight; // 计算偏移高度
//                }
//                singleImgRGB = image.getRGB(0, 0, width, imageHeight, null, 0, width);
//                imageResult.setRGB(0, shiftHeight, width, imageHeight, singleImgRGB, 0, width); // 写入流中
//            }
//            pdDocument.close();
//            File outFile = new File("test.jpg");
//            ImageIO.write(imageResult, "jpg", outFile);// 写图片
//
//            response.setContentType("multipart/form-data");
//            out = response.getOutputStream();
//            ips = new FileInputStream(outFile);
//            // 读取文件流
//            int len = 0;
//            byte[] buffer = new byte[1024 * 10];
//            while ((len = ips.read(buffer)) != -1) {
//                out.write(buffer, 0, len);
//            }
//            out.flush();
//        } catch (Exception e) {
//            LOGGER.error("... . . .-. 微信查询查询发票pdf异常", e);
//            e.printStackTrace();
//            return null;
//        } finally {
//            out.close();
//            ips.close();
//        }
//        return null;
//    }
//
//    /**
//     * 适用加油站的相关参数
//     */
//    @Override
//    public Map<String, Object> findOilStationParameter(HttpServletRequest request) throws Exception {
//        /*
//         * EsUserPO esUserPO = WechatUtil.getSessionUser(request); //查看该用户是否为特权用户 String
//         * cardId = oilCardMapper.findCardIdByUid(esUserPO.getUid());
//         */
//        Map<String, Object> resultMap = new HashMap<>();
//        JSONObject jsonObject = this.parseRequest(request);
//        String provinceName = jsonObject.getString("provinceName");
//        MarketPriceInfo marketPriceInfo = marketPriceMapper.findMarketPrice(provinceName);
//        if (marketPriceInfo != null) {
//            resultMap.put("marketPriceInfo", marketPriceInfo);
//        } else {
//            resultMap.put("marketPriceInfo", "");
//        }
//        List<HighWayPO> highWayList = new ArrayList<>();
//        /*
//         * if (StringUtils.isNotEmpty(cardId)) { highWayList = highWayMapper.list(new
//         * HighWayPO()); }else {
//         */
//        highWayList = highWayMapper.findHighWayList(provinceName);
//        // }
//
//        if (highWayList != null) {
//            for (HighWayPO highWayPO : highWayList) {
//                highWayPO.setHighwayCode(highWayPO.getHighwayCode() + "(" + highWayPO.getName() + ")");
//            }
//            resultMap.put("highWayList", highWayList);
//        } else {
//            resultMap.put("highWayList", "");
//        }
//        List<OilModelPO> oilModelList = oilModelMapper.list();
//        if (oilModelList != null) {
//            resultMap.put("oilModelList", oilModelList);
//        } else {
//            resultMap.put("oilModelList", "");
//        }
//        return resultMap;
//    }
//
//    @Override
//    public String updateGasStationImage() throws Exception {
//        List<OilStationPO> list = oilStationMapper.findGasStationImage();
//        LOGGER.info("... . . .-. 加油站图片记录数 {}", list.size());
//        for (OilStationPO oilStation : list) {
//            String absoluteFilePath = "D:\\pic\\oilcard\\gasolinebrand\\" + oilStation.getOilStationImage();
//            // 图片上传OSS
//            String fileUrl;
//            try {
//                fileUrl = upload(oilStation.getFullName(), absoluteFilePath);
//                oilStation.setOilStationImage(fileUrl);
//                oilStationMapper.updateGasStationImage(oilStation);
//            } catch (Exception e) {
//                LOGGER.error("构建加油站图片连接，图片上传OSS失败，加油站图片数据 {} {}", oilStation, e);
//                return null;
//            }
//        }
//        return null;
//    }
//
//    @Override
//    public String getWechatSharedSignature(HttpServletRequest request) throws Exception {
//        JSONObject jsonObject = parseRequest(request);
//        String url = jsonObject.getString("url");
//        LOGGER.info("当前请求的url地址{}",url);
//        // 随机数
//        String noncestr = WechatUtil.getMessageDigest(String.valueOf(new Random().nextInt(10000)).getBytes());
//        //时间戳
//        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
//
//        String jsapiTicket = WechatUtil.getJsapiTiket();
//        SortedMap<String, String> finalpackage = new TreeMap<String, String>();
//        finalpackage.put("noncestr",noncestr);
//        finalpackage.put("jsapi_ticket",jsapiTicket);
//        finalpackage.put("timestamp",timestamp);
//        finalpackage.put("url",url);
//        //签名算法
//        String signature = shaEncode(finalpackage);
//
//        JSONObject json = new JSONObject();
//        json.put("appid", SysParamsUtil.getSysParams(SysParamConstant.WECHAT_APPID));
//        json.put("timeStamp", timestamp);
//        json.put("nonceStr", noncestr);
//        json.put("signature", signature);
//        json.put("responseMsg", "ok");
//        return json.toJSONString();
//    }
//
//    public static String  shaEncode(SortedMap<String, String> packageParams) throws Exception {
//        StringBuffer sb = new StringBuffer();
//        Set es = packageParams.entrySet();
//        Iterator it = es.iterator();
//        while (it.hasNext()) {
//            Map.Entry entry = (Map.Entry) it.next();
//            String k = (String) entry.getKey();
//            String v = (String) entry.getValue();
//            if (null != v && !"".equals(v) && !"sign".equals(k)
//                    && !"key".equals(k)) {
//                sb.append(k + "=" + v + "&");
//            }
//        }
//        MessageDigest sha = null;
//        try {
//            sha = MessageDigest.getInstance("SHA");
//        } catch (Exception e) {
//            System.out.println(e.toString());
//            e.printStackTrace();
//            return "";
//        }
//        String str = sb.toString().substring(0,sb.toString().length()-1);
//        byte[] byteArray = str.getBytes("UTF-8");
//        byte[] md5Bytes = sha.digest(byteArray);
//        StringBuffer hexValue = new StringBuffer();
//        for (int i = 0; i < md5Bytes.length; i++) {
//            int val = ((int) md5Bytes[i]) & 0xff;
//            if (val < 16) {
//                hexValue.append("0");
//            }
//            hexValue.append(Integer.toHexString(val));
//        }
//        return hexValue.toString();
//    }
//
//    public String upload(String fileName, String fileAbsolutePath) throws Exception {
//        String url = "http://10.180.226.148:8080" + "/object/upload/encoded";
//        //String url = "http://10.183.34.15:8090" + "/object/upload/encoded";
//        Map<String, String> headers = new HashMap<>(2);
//        headers.put("Content-Type", "application/x-www-form-urlencoded");
//        headers.put("Authorization", "UpToken " + UP_TOKEN);
//
//        File file = new File(fileAbsolutePath);
//        byte[] buffer;
//        try (InputStream inputStream = new FileInputStream(file)) {
//            buffer = new byte[((int) file.length())];
//            inputStream.read(buffer);
//        } catch (IOException ex) {
//            throw ex;
//        }
//        String base64Str = Base64.getEncoder().encodeToString(buffer);
//        Map<String, String> map = new HashMap<>(2);
//        map.put("filename", fileName);
//        map.put("binary", base64Str);
//        String resp = HttpClientUtil.postForm(url, headers, map);
//        JSONObject jsonObject = JSON.parseObject(resp);
//        String key = jsonObject.getString("key");
//        return "https://oss.etcsd.com" + "/object/" + key;
//        //return "http://oss.test.etcsd.cn" + "/object/" + key;
//    }
//
//    private static String generateUpToken() {
//        /*
//         * token有效期  2119-01-17 16:34:02
//         * 公开资源
//         */
//        String policy = "{\"deadline\":4703387642, \"is_public_access\":1}";
//
//        // 对 JSON 编码的上传策略进行URL 安全的 Base64 编码，得到待签名字符串：
//        String encodedPolicy = Base64.getEncoder().encodeToString(policy.getBytes());
//
//        // 使用AccessKeySecret对上一步生成的待签名字符串计算HMAC-SHA1签名
//        try {
//            Mac mac = Mac.getInstance("HmacSHA1");
//
//            byte[] sk = "TnnbxMkzzvRzPwXqd3bWtbWzKRpnPjr4JRMx43PT".getBytes(Charset.forName("UTF8"));
//            //byte[] sk = "g7RRLJfXd7fTFhHb7m9tTctNKHCtxWnfmnhrLksN".getBytes(Charset.forName("UTF8"));
//            SecretKeySpec secretKeySpec = new SecretKeySpec(sk, "HmacSHA1");
//            mac.init(secretKeySpec);
//            String sign = Hex.encodeHexString(mac.doFinal(encodedPolicy.getBytes("utf-8")));
//            // 对签名进行URL 安全的 Base64 编码：
//            String encodedSign = Base64.getEncoder().encodeToString(sign.getBytes());
//
//            // 将AccessKeyId、encodedSign 和 encodedPolicy 用英文符号:连接起来：
//            String token = "zvjv93mv9q9gchhxbjmn" + ":" + encodedSign + ":" + encodedPolicy;
//            //String token = "pdn7svnkhkkpfgcgzx3w" + ":" + encodedSign + ":" + encodedPolicy;
//            return token;
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//    /**
//     * 发票打印后通知用户公众号
//     *
//     * @param billConsumePO
//     * @param title
//     */
//    private void sendToUserWechatAfterInvoicePrint(BillConsumePO billConsumePO, String title) {
//        ThreadUtil.execute(() -> {
//            if (LOGGER.isDebugEnabled()) {
//                LOGGER.debug("发票打印通知用户微信公众号 [{}]", billConsumePO.getOrderId());
//            }
//            OilCardPO oilCardPO = oilCardMapper.qry(billConsumePO.getCardId());
//            EsUserPO userPO = userInfoMapper.qry(oilCardPO.getUid());
//            GasStationPO gasStationPO = gasStationMapper.qryByTerminalId(billConsumePO.getTerminalId());
//            if (null == gasStationPO || ObjectUtils.isEmpty(gasStationPO.getGasStationId())) {
//                LOGGER.warn("发票打印通知用户微信公众号，加油站信息查询失败 [{}]", billConsumePO.getOrderId());
//                WechatMsgUtil.invoicePrint(userPO.getWechatOpenid(), "", billConsumePO.getConsumeAmount().toString(), title);
//                return;
//            }
//            OilStationPO oilStationPO = oilStationMapper.qry(gasStationPO.getGasStationId());
//            if (null == oilStationPO) {
//                LOGGER.warn("发票打印通知用户微信公众号，加油站信息查询失败 [{}]", billConsumePO.getOrderId());
//                WechatMsgUtil.invoicePrint(userPO.getWechatOpenid(), "", billConsumePO.getConsumeAmount().toString(), title);
//                return;
//            }
//            String amount = billConsumePO.getConsumeAmount().setScale(2, BigDecimal.ROUND_HALF_UP).toString();
//            WechatMsgUtil.invoicePrint(userPO.getWechatOpenid(), oilStationPO.getName(), amount, title);
//        });
//    }
//
//}
